package com.example.homelicaisystem.services.impl;

import com.example.homelicaisystem.dao.InvestmentDetailMapper;
import com.example.homelicaisystem.entity.InvestmentDetail;
import com.example.homelicaisystem.entity.DTO.InvestmentDetailDTO;
import com.example.homelicaisystem.entity.SelectResult;
import com.example.homelicaisystem.services.InvestmentDetailService;
import com.example.homelicaisystem.utils.UserUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class InvestmentDetailImpl implements InvestmentDetailService {
    private final InvestmentDetailMapper investmentDetailMapper;

    public InvestmentDetailImpl(InvestmentDetailMapper investmentDetailMapper) {
        this.investmentDetailMapper = investmentDetailMapper;
    }

    @Override
    public Page<InvestmentDetail> getList(InvestmentDetailDTO data) {

        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return investmentDetailMapper.getList(data);

    }

    @Override
    public void create(InvestmentDetail data) {
        int userId = UserUtil.getUserId();
        data.setUserId(userId);

        data.setDate(new Date());
        investmentDetailMapper.insert(data);


    }

    @Override
    public InvestmentDetail getInvestmentDetailById(int id) {
        return investmentDetailMapper.getInvestmentDetailById(id);
    }

    @Override
    public void delete(int id) {
        investmentDetailMapper.delete(id);
    }

//    @Override
//    public InvestmentDetail create(InvestmentDetail data) {
//        //记录当前时间
//        data.setDate(new Date());
//        //token获取id
//        int userId = UserUtil.getUserId();
//        data.setUserId(userId);
//        //插入收入明细表
//        investmentDetailMapper.insert(data);
//        return data;
//    }
//
//    @Override
//    public List<SelectResult> selectInvestType() {
//
//        return investmentDetailMapper.selectInvestType();
//    }
//
//    @Override
//    public void modify(InvestmentDetail data) {
//        investmentDetailMapper.update(data);
//    }
//
//    @Override
//    public InvestmentDetail getInvestById(int id) {
//        return investmentDetailMapper.getInvestById(id);
//    }
//
//    @Override
//    public void delete(int id) {
//        investmentDetailMapper.delete(id);
//    }
}
